'''
Created on 2012-8-22

@author: null
'''
import unittest
from web import app
from flask import json
import base64
import os

random_user_name = base64.urlsafe_b64encode(os.urandom(10));
random_email = random_user_name + "@test.com";

class BookTestCase(unittest.TestCase):
    def setUp(self):
        app.config['TESTING'] = True

    def tearDown(self):
        app.config['TESTING'] = False
        
    def test_get_user_by_email(self):
        email = "test@test.com";
        tester = app.test_client();
        response = tester.get("/api/user/email={0}".format(email),
                              content_type="application/json");
        print(str(response));
        print(str(response.data));
        self.assertTrue(response.status_code == 200);  
        
    def test_add_user(self):
        tester = app.test_client();
        body = json.dumps({"DisplayName":random_user_name, "Email":random_email, "Password": "test", "PhoneNumber":"12345678901"});
        response = tester.post("/api/user/add",
                               data = body,
                               content_type="application/json");
        print(str(response));
        print(str(response.data));
        self.assertTrue(response.status_code == 200); 
        
if __name__ == '__main__':
    unittest.main()
